package com.shop.loan.model;

import com.shop.loan.proxy.MachineUserProxy;
import com.shop.loan.util.LoanOrderUtil;
import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_erupt.RowOperation;
import xyz.erupt.annotation.sub_erupt.Tpl;
import xyz.erupt.annotation.sub_field.*;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.annotation.sub_field.sub_edit.VL;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

@Setter
@Getter
@Entity
@Table(name = "s_machine_rule_log",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = "user_id")
        })
@Erupt(
        name = "机审规则记录",
        orderBy = "updateTime desc",
        power = @Power(add = false, delete = false, edit = false, viewDetails = false),
        dataProxy = MachineUserProxy.class,
        rowOperation = {
                @RowOperation(
                        title = "用户详情",
                        icon = "fa fa-user",
                        mode = RowOperation.Mode.SINGLE,
                        tpl = @Tpl(
                                path = "/tpl/userDetailByUser.html",
                                width = "50%",
                                engine = Tpl.Engine.Thymeleaf
                        ),
                        type = RowOperation.Type.TPL
                ),
        }
)

public class MachineUser extends BaseModel {

    @EruptField(
            views = @View(title = "用户id", width = LoanOrderUtil.orderListByIdWidth),
            edit = @Edit(title = "用户id", notNull = true)
    )
    @Column(name = "user_id")
    private Long userId;

    @Transient
    @EruptField(
            views = @View(title = "用户", type = ViewType.SAFE_TEXT, width = LoanOrderUtil.orderListByUserWidth)
    )
    private String userInfo;


    @Transient
    @EruptField(
            edit = @Edit(title = "姓名", search = @Search(vague = true))
    )
    private String userName;


    @Transient
    @EruptField(
            edit = @Edit(title = "手机号码", search = @Search(vague = true))
    )
    private String userPhone;


    @EruptField(
            views = @View(title = "机审时间",width = LoanOrderUtil.orderListByOrderLocationWidth),
            edit = @Edit(title = "机审时间",
                    search = @Search(vague = true),
                    readonly = @Readonly,
                    dateType = @DateType(type = DateType.Type.DATE_TIME))
    )
    private Date updateTime;


    @Transient
    @EruptField(
            views = @View(title = "渠道", column = "name", width = LoanOrderUtil.orderListByChannelWidth),
            edit = @Edit(
                    title = "渠道",
                    search = @Search(vague = true),
                    type = EditType.REFERENCE_TREE
            )
    )
    private Channel channel;

    @Lob
    @EruptField(
            views = @View(title = "规则详情", show = false),
            edit = @Edit(title = "规则详情", notNull = true)
    )
    private String ruleDetail;

    @Transient
    @EruptField(
            views = @View(title = "客户类型", width = LoanOrderUtil.orderListByPayMoneyWidth),
            edit = @Edit(
                    title = "客户类型",
                    type = EditType.CHOICE,
                    search = @Search,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "新客", value = "0"),
                                    @VL(label = "老客", value = "1"),
                            }
                    )
            )
    )
    private String userType;


    @Transient
    @EruptField(
            edit = @Edit(
                    title = "机审状态",
                    type = EditType.CHOICE,
                    search = @Search,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "通过", value = "1"),
                                    @VL(label = "拒绝", value = "2"),
                            }
                    )
            )
    )
    private Integer machineStatus;

    private BigDecimal score;

    @Transient
    @EruptField(
            views = @View(title = "机审备注", type = ViewType.SAFE_TEXT, width = "250px")
    )
    private String machineRemark;


    @Transient
    @EruptField(
            views = @View(title = "订单状态")
    )
    private String orderRemark;

}
